﻿using System;
using System.Collections.Generic;
using System.Xml;
using UnityEditor;
using UnityEngine;

namespace EditorFramework
{
    [CustomEditorWindow(7)]
    public class XMLGUIExample : EditorWindow
    {
        const string XMLFilePath = "Assets/EditorFramework/Example/7_XMLGUI/Editor/GUILayoutExample.xml";
        private string mXMLContent;
        private XMLGUI mXmlgui;
        
        private void OnEnable()
        {
            var xmlFileAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(XMLFilePath);
            mXMLContent = xmlFileAsset.text;
            
            mXmlgui = new XMLGUI();
            mXmlgui.ReadXML(mXMLContent);
            
            mXmlgui.GetGUIBaseByID<XMLGUILayoutButton>("Button").OnClick += () => Debug.Log("Button1 Clicked!");
        }
        private void OnGUI()
        {
            mXmlgui.Draw();
        }
    }
}